#include <iostream>

struct request  //涨薪请求
{
    int money;
};

class Manager  //抽象上级
{
public:
    Manager(const std::string name) : name(name) {};
    void SetManager(Manager *m)   //设置你的上级
    {
        this->m = m;
    }
    virtual void GetRequest(request *r) = 0;  //处理请求
protected:
    std::string name;
    Manager *m;  //直接上级指针
};

class CommonManager : public Manager //普通经理
{
public:
    using Manager::Manager;
    void GetRequest(request *r)
    {
        if(r->money <= 500)
        {
            std::cout << name << "批准了" << r->money << "的涨薪请求"<< std::endl;
        }
        else
        {
            m->GetRequest(r);
        }
    }
};

class Major : public Manager  //总监
{
public:
    using Manager::Manager;
    void GetRequest(request *r)
    {
        if(r->money > 500 && r->money <= 1000)
        {
            std::cout << name << "批准了" << r->money << "的涨薪请求"<< std::endl;
        }
        else
        {
            m->GetRequest(r);
        }
    }
};

class GeneralManager  : public Manager  //总经理
{
public:
    using Manager::Manager;
    void GetRequest(request *r)
    {
        if(r->money > 1000)
        {
            std::cout << name << "批准了" << r->money << "的涨薪请求"<< std::endl;
        }
    }
};

int main()
{
    Manager *m1 = new CommonManager("张经理");
    Manager *m2 = new Major("李总监");
    Manager *m3 = new GeneralManager("王总");

    //形成责任链
    m1->SetManager(m2);
    m2->SetManager(m3);

    request *r = new request;
    r->money = 1500;
    m1->GetRequest(r);  //把请求给普通经理，普通经理处理不了，交给总监，总监处理不了，交给总经理
    return 0;
}